<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Minim : : Pan</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body> 
<center>
<table class="mainTable">
  <tr>
    <td class="header">
    	<span class="indexheader">Minim</span><br/>
    	<span class="indexnavigation">
    		<a href="index.html">core</a> | 
    		<a href="index_ugens.html">ugens</a> | 
    		<a href="index_analysis.html">analysis</a>
    	</span>
    </td>
    <td class="border-left">&nbsp;</td>
  </tr>
  
  <tr>
    <td class="classNavigation">
    	<p class="mainTextName">Pan</p>
    	
       <p class="linkListHeader">Fields</p>
       <p class="linkList">
           
    <a href="pan_field_pan.html" title="UGens patched to this input should generate values between -1 and +1.">pan</a><br/>
    
	   </p>
   
    	
       <p class="linkListHeader">Methods</p>
       <p class="linkList">
           
    <a href="pan_method_channelcount.html" title="Returns the number of channels this UGen has been configured to generate.">channelCount ( )</a><br/>
    
    <a href="pan_method_getlastvalues.html" title="Return the last values generated by this UGen. This will most often be
 used by sub-classes when pulling data from their inputs.">getLastValues ( )</a><br/>
    
    <a href="pan_method_patch.html" title="Send the output of this UGen to another UGen, UGenInput, or AudioOutput.">patch ( )</a><br/>
    
    <a href="pan_method_printinputs.html" title="Prints all inputs connected to this UGen (for debugging)">printInputs ( )</a><br/>
    
    <a href="pan_method_samplerate.html" title="Returns the sample rate of this UGen.">sampleRate ( )</a><br/>
    
    <a href="pan_method_setchannelcount.html" title="Let this UGen know how many channels of audio you will be asking it for.">setChannelCount ( )</a><br/>
    
    <a href="pan_method_setpan.html" title="Set the pan value of this Pan. Values passed to this method should be
 between -1 and +1. This is equivalent to calling the setLastValue method 
 on the pan input directly.">setPan ( )</a><br/>
    
    <a href="pan_method_setsamplerate.html" title="Set the sample rate for this UGen.">setSampleRate ( )</a><br/>
    
    <a href="pan_method_tick.html" title="Generates one sample frame for this UGen.">tick ( )</a><br/>
    
    <a href="pan_method_unpatch.html" title="Unpatch this UGen from an AudioOutput or other UGen.">unpatch ( )</a><br/>
    
	   </p>
   
    </td>
    <td class="mainText border-left">
    	A UGen for panning a mono signal in a stereo field.
 Because of the generally accepted meaning of pan,
 this UGen strictly enforces the channel count of its 
 input and output. Anything patched to the audio input 
 of Pan will be configured to generate mono audio, and when 
 Pan is patched to any other UGen, it will throw an 
 exception if that UGen tries to set Pan's channel count 
 to anything other than 2.
    	<p class="memberSectionHeader">Constructors</p>
    	<pre><em>Construct a Pan UGen with a specific starting pan value.</em>
Pan(float panValue)
</pre>
    	
   <p class="memberSectionHeader">Parameters</p>
   
        <span class="parameterName">panValue</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">float: a value of 0 means to pan dead center, 
            -1 hard left, and 1 hard right.</span><br/>
    
   
    	<p class="memberSectionHeader">Related</p>
    	<A href="ugen_class_ugen.html">UGen</A><BR>
<A href="balance_class_balance.html">Balance</A><BR>

    	<p class="memberSectionHeader">Example</p>
    	<pre>/* panExample&lt;br/>
   is an example of using the Pan UGen inside an Instrument.
   The Instrument is designed to play a single tone that is panned 
   back and forth across the stereo field based on the value of a 
   low frequency oscillator (LFO). An LFO is simply an Oscil that 
   has a frequency that is usually well below audible range.
   &lt;p>
   This sketch uses the Instrument to play two notes, one which 
   slowly pans back and forth across the entire stereo field (-1, 1)
   and one which more quickly pans back and forth between a 
   smaller range.
   &lt;p>
   For more information about Minim and additional features, 
   visit http://code.compartmental.net/minim/
   &lt;p>
   author: Damien Di Fede
*/

// import everything necessary to make sound.
import ddf.minim.*;
import ddf.minim.ugens.*;

// create all of the variables that will need to be accessed in
// more than one methods (setup(), draw(), stop()).
Minim minim;
AudioOutput out;

// define a PanInstrument that implements the Instrument interface
// so that we can use instances of it with playNote
class PanInstrument implements Instrument
{
  // create all variables that must be used throughout the class
  Oscil sineOsc, LFO;
  Pan pan;
  
  // constructors for this intsrument
  PanInstrument( float oscFrequency, float oscAmplitude, float lfoFrequency, float lfoAmplitude )
  {    
    // create new instances of any UGen objects as necessary
    sineOsc = new Oscil( oscFrequency, oscAmplitude, Waves.SINE );
    
    // the arguments to the Pan UGen are for the balance and width.
    // balance ranges from -1 to 1, which basically are hard-left and 
    // hard-right, respectively.
    // we create our pan with 0 because we will drive the value of 
    // the balance using Pan's balance UGenInput.
    pan = new Pan(0);
    
    // LFO stands for low frequency oscillator. we will use this to control
    // the balance input of the Pan Ugen.
    LFO = new Oscil( lfoFrequency, lfoAmplitude, Waves.SINE );
        
    // patch everything together up to the final output
    sineOsc.patch( pan );
    LFO.patch( pan.pan );
  }
  
  // every instrument must have a noteOn( float ) method
  void noteOn( float dur )
  {
    // and patch to the output
    pan.patch( out );
  }
  
  // every instrument must have a noteOff() method
  void noteOff()
  {
    // and unpatch the output 
    // this causes the entire instrument to stop calculating sampleframes
    // which is good when the instrument is no longer generating sound.
    pan.unpatch( out );
  }
}

// setup is run once at the beginning
void setup()
{
  // initialize the drawing window
  size( 512, 200, P2D );
  
  // initialize the minim and out objects
  minim = new Minim( this );
  // because we are using a Pan UGen, we need a stereo output.
  out = minim.getLineOut( Minim.STEREO, 1024 );
  
  // initialize the myNote object as a PanInstrument
  PanInstrument myNote = new PanInstrument( 587.3f, 0.5, 0.5, 1.0 );
  
  // play a note with the myNote object
  out.playNote( 0.5, 2.6, myNote );
  
  // give a new note value to myNote
  myNote = new PanInstrument( 415.3f, 0.5, 3.0, 0.5 );
  
  // play another note with the myNote object
  out.playNote(3.5, 2.6, myNote );
}

// draw is run many times
void draw()
{
  // erase the window to black
  background( 0 );
  // draw using a white stroke
  stroke( 255 );
  // draw the waveforms
  for( int i = 0; i &lt; out.bufferSize() - 1; i++ )
  {
    // find the x position of each buffer value
    float x1  =  map( i, 0, out.bufferSize(), 0, width );
    float x2  =  map( i+1, 0, out.bufferSize(), 0, width );
    // draw a line from one buffer position to the next for both channels
    line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
  }  
}
</pre>
    	<p class="memberSectionHeader">Usage</p>
    	Web & Application
    </td>
  </tr>
</table>
</center>
</body>
</html>